﻿<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link rel="stylesheet" type="text/css" media="screen" href="css/redmond/jquery-ui-1.10.3.custom.min.css" />	<!-- jqueryUI CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />							<!-- jqGrid CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/selfTemplate.css" />						<!-- 本專案自行定義 CSS -->

<script src="js/jquery-1.10.2.min.js"></script>		<!-- jQuery 核心 -->
<script src="js/grid.locale-tw.js" type="text/javascript"></script>											<!-- jqGrid 語系檔 -->
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>										<!-- jqGrid 核心 -->
<script src="js/jquery-ui-1.10.3.custom.js" type="text/javascript"></script>							<!-- jqueryUI 核心 -->
<script src="js/jquery.cookie.js"></script>																	<!-- 操作cookie用 -->
<script src="js/widgets.js" type="text/javascript"></script>												<!-- 本專案自行定義 JS -->

<title>維護需求</title>

<script type="text/javascript">


function checkDuplicated() {
	var reqId = $("#reqId").val();
	var ll = $("#gd").jqGrid('getDataIDs');
	var isDuplicated = false;
	for(var i=0;i<ll.length;i++){
		if (ll[i] == reqId ) {
			isDuplicated = true;
		}
	}
	
	if (isDuplicated) {
		alert(reqId+"已經存在，需求編號不可重覆 !");
	} else {
		var reqDesc = $("#reqDesc").val();
		var dataAdd = {"reqId":reqId,"reqDesc":reqDesc};
		var _iCount = $("#gd").jqGrid('getGridParam', 'records');
		$("#gd").jqGrid('addRowData', _iCount+1,dataAdd);
		$("form#kk input#reqId").val( reqId ) ;
	} 
	return [];
}


	

$(document).ready(function() {
	
	init("reqs.html");
	var t = querySubsys( $.cookie("empId"),$.cookie("pageName"),"subsysId",$.cookie("localSystemId"));
	
	if ( t == 1 ) {
		windowFreeze("畫面初始中");
		/*	綁定 下拉吧 選擇的事件 */ 
		selectSubSys("QueryReqJqGrid");
		
		
		$("#gd").jqGrid({
			url:'QueryReqJqGrid',
			postData: { subsysId: $('select#subsysId option:selected').val() },
			datatype: "json",
			type: "post",
		   	colNames:['需求名稱','需求ID','創建系統'],
		   	colModel:[
		   		{name:'reqDesc',index:'reqDesc',editable:true,editrules:{required:true}},
		   		{name:'reqId',index:'reqId',editable:false},
		   		{name:'sysSN'}
		   	],
		   	resizable : false,
		   	rowNum:6,
		   	pager: '#pager',
		   	rownumbers: true,
		   	viewrecords: true,	
			editurl: "ManipulateGridReq",
		    caption:"設定需求"
			}).navGrid('#pager',{add:true,edit:true,del:true,search:false,refresh:false}
			,{	// 修改
				editData:{ 
					reqSN: function() {
						var sel_id = $("#gd").jqGrid('getGridParam', 'selrow');
						return $("#gd").jqGrid('getCell', sel_id, 'reqSN');
					},
					currentUser: function() { return $.cookie("userId"); }
				},
				onclickSubmit:function() {
					var reqId = $("#reqId").val();
					var reqDesc = $("#reqDesc").val();
					var reqSN = $("#reqSN").val();
					var dataAdd = {"reqId":reqId,"reqDesc":reqDesc,"reqSN":reqSN};
					var sel_id = $("#gd").jqGrid('getGridParam', 'selrow');
					var id =  $("#gd").jqGrid('getCell', sel_id, 'id');
					$("#gd").jqGrid('setRowData', id,dataAdd);
				}
			}
			,{	//新增
				editData:{ 
					currentUser: function() { return $.cookie("userId"); }
				},
				onclickSubmit:function() {
					checkDuplicated();
				}
			}
			,{	//刪除
				delData: { 
					reqSN: function() {
						var sel_sn = $("#gd").jqGrid('getGridParam', 'selrow');
						return $("#gd").jqGrid('getCell', sel_sn, 'reqSN');
					},
					currentUser: function() { return $.cookie("userId"); }
				}
			}
		);
		
		windowUnfreeze();
	}
	

	
}).tooltip();

</script>

</head>
<body>
	<div id="header"></div>

	<table>
		<thead class="tableFirst">
			<tr>
				<th class="right"><label for="subsys">子系統：</label></th>
				<td><select id="subsysId"><option id='dOpt'>--請選擇--</option></select></td>
			</tr>
		</thead>
	</table>

	<p>
	<p>

	<table id="gd"></table>
	<div id="pager"></div>
	<form id="kk">
		<input id="reqId" type="hidden"> <input id="reqDesc" type="hidden">
		<input id="reqSN" type="hidden">
	</form>

</body>
</html>